// releasePage/pages/homePageInfo/addressName/addressName.js
const app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        ipxBottom: 0,
        current: Number,
        nfcAddressNameValue: '',
        nfcAddressNamelength: 0,
        placeholder: '如：四号出口从左至右三号机/717新模范马路站',
        maxlength: 20,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            current: options.current,
            nfcAddressNameValue: options.nfcAddressName,
            nfcAddressNamelength: options.nfcAddressName.length,
        });
        if (app.globalData.isIpx) {
            this.setData({
                ipxBottom: 34,
            });
        }
        if (options.current != 2) {
            this.setData({
                placeholder: '请输入线路名称',
                maxlength: 10,
            });
            wx.setNavigationBarTitle({
                title: '路线名称',
            });
        }
        if (options.current == 2) {
            this.setData({
                placeholder: '请描述闸机/刷卡位置',
                maxlength: 10,
            });
            wx.setNavigationBarTitle({
                title: '刷卡地点',
            });
        } else {
            wx.setNavigationBarTitle({
                title: '地点名称',
            });
        }
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    addressInput: function (e) {
        this.setData({
            nfcAddressNameValue: e.detail.value,
            nfcAddressNamelength: e.detail.value.length,
        });
        app.numLimitTip(e.detail.value.length, this.data.maxlength);
    },
    backTap(e) {
        if (this.data.nfcAddressNameValue) {
            let pages = getCurrentPages();
            let prevPage = pages[pages.length - 2];
            if (this.data.current == 2) {
                prevPage.setData({
                    nfcAddressName: this.data.nfcAddressNameValue,
                });
            } else if (this.data.current == 1) {
                prevPage.setData({
                    ftLineName: this.data.nfcAddressNameValue,
                });
            } else {
                prevPage.setData({
                    nfcLineName: this.data.nfcAddressNameValue,
                });
            }
            wx.navigateBack({
                delta: 1, // 返回上一级页面。
            });
        } else {
            wx.showToast({
                title: '请将信息填写完整',
                icon: 'none',
                duration: 1500,
            });
        }
    },
});
